package com.cake.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cake.base.config.Constant;
import com.cake.base.util.ReturnUtils;
import com.cake.entity.XxAdmin;
import com.cake.service.inter.IXxAdminService;

/**
 * 登录控制层
 * @author Administrator
 *
 */
@RequestMapping(value = "login")
@Controller
public class LoginController {
	
	@Autowired
	private IXxAdminService xxAdminService;
	
	/**
	 * 后台人员登录
	 * @return
	 */
	@PostMapping(value = "loginForAdmin")
	public @ResponseBody Object loginForAdmin(@RequestBody XxAdmin xxAdmin, HttpServletRequest request){
		return xxAdminService.loginForAdmin(xxAdmin, request);
	}
	
	/**
	 * 后台人员注销
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@GetMapping(value = "logoutForAdmin")
	public @ResponseBody Object logoutForAdmin(HttpServletRequest request, HttpServletResponse response) throws Exception{
		request.getSession().removeAttribute(Constant.USER_SESSION_KEY);
		return ReturnUtils.forNoraml("000000", "操作成功");
	}
	
}
